//
//  YHContributionCell.m
//  Catches
//
//  Created by jiangqiong on 2018/5/17.
//  Copyright © 2018年 solot. All rights reserved.
//

#import "YHContributionCell.h"
#import "YHContributionerModel.h"


@interface YHContributionCell()
@property (nonatomic , strong)YHContributionerModel * model;

@property (nonatomic , strong)UILabel * labAddress;
@property (nonatomic , strong)UIImageView * imgFlag;
@property (nonatomic , strong)UILabel * labName;
@property (nonatomic , strong)UIImageView * avaterImg;

@property (nonatomic , strong)UILabel * labRank;
@property (nonatomic , strong)UILabel * labLevel;
@property (nonatomic , strong)UILabel * labContribute;
@end

@implementation YHContributionCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self loadSubview];
    }
    return self;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self loadSubview];
    }
    return self;
}

- (void)loadSubview {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UILabel * rankLab = [UILabel new];
    [self.contentView addSubview:rankLab];
    rankLab.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    rankLab.text = @"3";
    rankLab.textColor = [UIColor yellowColor];
    [rankLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.width.mas_equalTo(30);
        make.leading.offset(10);
        
    }];
    self.labRank = rankLab;
  
    
    UIView * line = [UIView new];
    line.backgroundColor = COLOR_WITH_HEX(0xdadada);
    [self.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.bottom.offset(0);
        make.leading.offset(10);
        make.height.mas_equalTo(0.5);
    }];
    
    
    UIImageView * avaterImg = [UIImageView new];
    [self.contentView addSubview:avaterImg];
    [avaterImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(60);
        make.centerY.offset(0);
        make.leading.mas_equalTo(rankLab.mas_trailing).offset(2);
    }];
    avaterImg.layer.masksToBounds = YES;
    avaterImg.layer.cornerRadius = 30;
    avaterImg.layer.borderColor = [UIColor orangeColor].CGColor;
    avaterImg.layer.borderWidth = 2;
    avaterImg.image = [UIImage imageNamed:@"mine_bags_vip"];
    self.avaterImg = avaterImg;
    
    UILabel * nameLab = [UILabel new];
    nameLab.textColor = COLOR_WITH_HEX(0x333333);
    nameLab.font = [UIFont systemFontOfSize:16];
    nameLab.text = @"星辰大海";
    [self.contentView addSubview:nameLab];
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(avaterImg.mas_trailing).offset(10);
        make.top.offset(20);
    }];
    self.labName = nameLab;
    
    UILabel * levelLab = [UILabel new];
    levelLab.textColor = COLOR_WITH_HEX(0xffffff);
    levelLab.backgroundColor = COLOR_WITH_HEX(0x666666);
    levelLab.font = [UIFont systemFontOfSize:12];
    levelLab.text = @"   院士   ";
    [self.contentView addSubview:levelLab];
    [levelLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(avaterImg.mas_trailing).offset(10);
        make.top.mas_equalTo(nameLab.mas_bottom).offset(10);
        make.height.mas_equalTo(18);
    }];
    levelLab.layer.masksToBounds = YES;
    levelLab.layer.cornerRadius = 9;
    self.labLevel = levelLab;
    
    UIImageView * flagImg = [UIImageView new];
    self.imgFlag = flagImg;
    [self.contentView addSubview:flagImg];
    flagImg.image = [UIImage imageNamed:@"mine_bags_tools"];
    [flagImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(10);
        make.leading.mas_equalTo(avaterImg.mas_trailing).offset(10);
        make.top.mas_equalTo(levelLab.mas_bottom).offset(10);
    }];
    
    UILabel * addressLab = [UILabel new];
    self.labAddress = addressLab;
    [self.contentView addSubview:addressLab];
    addressLab.textColor = [UIColor grayColor];
    addressLab.font = [UIFont systemFontOfSize:10];
    addressLab.text = @"成都";
    [addressLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(flagImg.mas_centerY).offset(0);
        make.leading.mas_equalTo(flagImg.mas_trailing).offset(10);
    }];
    
    UILabel * contributionLab = [UILabel new];
    [self.contentView addSubview:contributionLab];
    contributionLab.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
    contributionLab.text = @"3873";
    contributionLab.textAlignment = NSTextAlignmentRight;
    contributionLab.textColor = [UIColor grayColor];
    [contributionLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.trailing.offset(-10);
    }];
    self.labContribute = contributionLab;
    
    
}

-(void)installModel:(YHContributionerModel *)model{
    self.model = model;
    if(model.areaType == YHContributionAreaType_area){
        [self areaFaramChange];
    }
    
    self.labRank.text = [NSString stringWithFormat:@"%ld",model.rank];
    [self.avaterImg setImageWithImageId:model.avatar];
    self.labName.text = model.nickname;
    self.labLevel.text = @"快点减肥打卡";
    self.labContribute.text = [NSString stringWithFormat:@"%ld",model.contributiveScore];
    
   
    
    if(model.rank == 2){
        self.labRank.textColor = COLOR_WITH_HEX(0xdadada);
        self.avaterImg.layer.borderColor = COLOR_WITH_HEX(0xdadada).CGColor;
        
    }else if (model.rank == 3){
        self.labRank.textColor = [UIColor orangeColor];
        self.avaterImg.layer.borderColor = [UIColor orangeColor].CGColor;
        
    }else{
        self.labRank.textColor = [UIColor blackColor];
        self.avaterImg.layer.borderColor =[UIColor clearColor].CGColor;
        
    }
}

-(void)areaFaramChange{
    self.labAddress.hidden = YES;
    self.imgFlag.hidden = YES;
    [self.labName mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.avaterImg.mas_trailing).offset(10);
        make.top.offset(30);
    }];
}


@end
